﻿using System;

namespace _6
{
    // 定义动物类
    public class Animal
    {
        // voice方法
        public virtual void Voice()
        {
            Console.WriteLine("动物发出声音");
        }
    }

    // 定义Cat类，继承Animal
    public class Cat : Animal
    {
        // 实现voice方法
        public override void Voice()
        {
            Console.WriteLine("喵喵喵");
        }
    }

    // 定义Pig类，继承Animal
    public class Pig : Animal
    {
        // 实现voice方法
        public override void Voice()
        {
            Console.WriteLine("哼哼哼");
        }
    }

    // 定义Dog类，继承Animal
    public class Dog : Animal
    {
        // 实现voice方法
        public override void Voice()
        {
            Console.WriteLine("汪汪汪");
        }
    }

    // 定义Store（宠物店）类
    public class Store
    {
        // getInstance方法，根据传入的字符串返回相应的动物对象
        public Animal GetInstance(string animalType)
        {
            if (animalType.ToLower() == "dog")
            {
                return new Dog();
            }
            else if (animalType.ToLower() == "pig")
            {
                return new Pig();
            }
            else
            {
                return new Cat();
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // 创建宠物店对象
            Store petStore = new Store();

            // 测试获取不同的动物对象并调用voice方法
            Console.WriteLine("获取Dog对象:");
            Animal dog = petStore.GetInstance("dog");
            dog.Voice();

            Console.WriteLine("\n获取Pig对象:");
            Animal pig = petStore.GetInstance("pig");
            pig.Voice();

            Console.WriteLine("\n获取Cat对象:");
            Animal cat = petStore.GetInstance("cat");
            cat.Voice();

            Console.WriteLine("\n测试未知动物类型:");
            Animal unknown = petStore.GetInstance("unknown");
            unknown.Voice();

            Console.WriteLine("\n测试大小写:");
            Animal dog2 = petStore.GetInstance("DOG");
            dog2.Voice();

           
        }
    }
}